<#--字段声明-->
<#--项目基础包名-->
<#assign AppPackageName = "${cfg.AppPackage}">
<#assign BaseMoudleName = "${package.ModuleName}">
<#assign ModulePackageName = "${cfg.ModulePackage}">
<#assign EntityPrefixName = "${entity?substring(0,entity?length-cfg.EntitySuffix?length)}">
<#--Service-->
<#assign ServiceName = "${table.serviceName}">
<#assign ServiceVarName = "${table.serviceName?uncap_first}">
<#assign ServicePackage = "${package.Service}">
<#--BO-->
<#assign BoName = "${EntityPrefixName}${cfg.BoSuffix}">
<#assign BoPackage = "${ModulePackageName}.${cfg.BoPackageName}">
<#--DTO-->
<#assign DtoName = "${EntityPrefixName}${cfg.DtoSuffix}">
<#assign DtoPackage = "${ModulePackageName}.${cfg.DtoPackageName}">
<#--Controller-->
<#--存在一个问题,'-'写死-1的问题 -->
<#assign CustomHyphen = "${controllerMappingHyphen?substring(0,controllerMappingHyphen?length-cfg.EntitySuffix?length-1)}">
<#--fix：修复写死-1的问题-->
<#if cfg.EntitySuffix?length==0 >
    <#assign CustomHyphen = "${controllerMappingHyphen?substring(0,controllerMappingHyphen?length-cfg.EntitySuffix?length)}">
</#if>
<#assign AuthPreFix = "${BaseMoudleName}:${CustomHyphen}">
<#--正文-->
package ${package.Controller};

<#--框架依赖，一般不变-->
import ${AppPackageName}.common.core.vo.PageData;
import ${AppPackageName}.common.valid.groups.*;
import ${AppPackageName}.common.web.annotation.ApiResult;

<#--模块内部依赖-->
import ${ServicePackage}.${ServiceName};
import ${BoPackage}.${BoName};
import ${DtoPackage}.${DtoName};
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

<#--Swagger依赖-->
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

<#--Spring依赖-->
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
<#if !restControllerStyle>
import org.springframework.stereotype.Controller;
</#if>

<#--JSR303依赖及JDK自带依赖-->
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import java.util.List;

/**
 * ${table.comment!} 前端控制器
 *
 * @author ${author}
 * @since ${date}
 */
@Api(tags = "${table.comment!}-相关接口")
@ApiResult
@Validated
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${CustomHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass}<${table.serviceName},${entity}>{
    <#else>
public class ${table.controllerName} {
    </#if>

    private final ${ServiceName} ${ServiceVarName};

    @Autowired
    public ${table.controllerName}(${ServiceName} ${ServiceVarName}) {
        this.${ServiceVarName} = ${ServiceVarName};
    }

    //-------接口-------

    @GetMapping("/{id}")
    @ApiOperation("获取一条${table.comment!}记录")
    public ${BoName} readById(@ApiParam("${table.comment!}Id") @PathVariable @Min(1) Long id) {
        return ${ServiceVarName}.readById(id);
    }

    @GetMapping("/ids")
    @ApiOperation("获取${table.comment!}记录列表--Id数组")
    public List<${BoName}> readByIds(@ApiParam("3D自建房Id数组") @RequestParam @NotEmpty List<Long> ids) {
        return ${ServiceVarName}.readByIds(ids);
    }

    @GetMapping("/list")
    @ApiOperation("获取${table.comment!}记录列表--条件")
    public List<${BoName}> readList(@Validated(Read.class) ${DtoName} condition) {
        return ${ServiceVarName}.readList(condition);
    }

    @PostMapping("/page")
    @ApiOperation("获取${table.comment!}记录列表--分页条件")
    public PageData<${BoName}> readPage(@ApiParam("页码") @RequestParam @NotNull @Min(1) Long pageNum,
                                        @ApiParam("每页大小") @RequestParam @NotNull @Min(1) @Max(100) Long pageSize,
                                        @ApiParam("查询条件") @RequestBody @Validated(Paging.class) ${DtoName} condition) {
        return ${ServiceVarName}.readPage(pageNum, pageSize, condition);
    }

    @PostMapping("/")
    @ApiOperation("新建一条${table.comment!}记录")
    @PreAuthorize("@auth.hasAuthority('${AuthPreFix}:create')")
    public Long createOne(@ApiParam("${table.comment!}DTO信息") @RequestBody @Validated({Default.class, Create.class}) ${DtoName} dto) {
        return ${ServiceVarName}.createOne(dto);
    }

    @PutMapping("/{id}")
    @ApiOperation("更新一条${table.comment!}记录")
    @PreAuthorize("@auth.hasAuthority('${AuthPreFix}:update')")
    public Long updateOne(@ApiParam("${table.comment!}Id") @PathVariable @Min(1) Long id,
                          @ApiParam("修改信息") @RequestBody @Validated({Default.class, Update.class}) ${DtoName} dto) {
        return ${ServiceVarName}.updateOne(id, dto);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除一条${table.comment!}记录")
    @PreAuthorize("@auth.hasAuthority('${AuthPreFix}:delete')")
    public Long deleteById(@ApiParam("${table.comment!}Id") @PathVariable @Min(1) Long id) {
        return ${ServiceVarName}.deleteById(id);
    }

    @DeleteMapping("/")
    @ApiOperation("删除批量${table.comment!}记录--Id数组")
    @PreAuthorize("@auth.hasAuthority('${AuthPreFix}:delete')")
    public List<Long> deleteByIds(@ApiParam("${table.comment!}Id数组") @RequestParam @NotEmpty List<Long> ids) {
        return ${ServiceVarName}.deleteByIds(ids);
    }

}

</#if>